//订单接口

import type {
  OrderCreateParams,
  OrderCreateResult,
  OrderListParams,
  OrderListResult,
  OrderLogisticResult,
  OrderNowParams,
  OrderPreResult,
  OrderResult,
} from '@/types/order'
import { http } from '@/utils/http'

/**
 *填写订单-获取预付订单
 * @returns
 */
export const getOrderPreAPI = () => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre',
  })
}

/**
 *填写订单-获取立即购买订单
 * @param data 请求参数
 * @returns
 */
export const getOrderPreNowApi = (data: OrderNowParams) => {
  return http<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre/now',
    data,
  })
}

/**
 *填写订单-获取再次购买订单
 * @param id 订单id
 * @returns
 */
export const getOrderRepurchaseByIdApi = (id: string) => {
  return http<OrderPreResult>({
    method: 'GET',
    url: `/member/order/repurchase/${id}`,
  })
}

/**
 * 提交订单
 * @param data 请求参数
 * @returns
 */
export const postMemberOrderApi = (data: OrderCreateParams) => {
  return http<OrderCreateResult>({
    method: 'POST',
    url: '/member/order',
    data,
  })
}

/**
 * 根据订单id获取订单详情信息
 * @param id 订单id
 * @returns
 */
export const getOrderByIdAPI = (id: string) => {
  return http<OrderResult>({
    method: 'GET',
    url: `/member/order/${id}`,
  })
}

/**
 * 模拟发货
 * @param id 订单id
 * @returns 返回提示语
 */
export const orderConsignmentByIdApi = (id: string) => {
  return http<string>({
    method: 'GET',
    url: `/member/order/consignment/${id}`,
  })
}

/**
 * 根据id确认收货
 * @param id 订单id
 * @returns
 */
export const orderReceiptByIdApi = (id: string) => {
  return http<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`,
  })
}

/**
 * 获取订单物流
 * @param id 订单id
 * @returns
 */
export const getOrderLogisticsByIdApi = (id: string) => {
  return http<OrderLogisticResult>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}

/**
 * 删除订单信息
 * @param ids 删除订单的id
 * @returns 提示语
 */
export const deleteOrderApi = (ids: string[]) => {
  return http<string>({
    method: 'DELETE',
    url: '/member/order',
    data: { ids },
  })
}

/**
 * 根据订单id取消订单
 * @param id 订单id
 * @param cancelReason  取消原因
 * @returns
 */
export const cancelOrderByIdApi = (id: string, cancelReason: string) => {
  return http<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/cancel`,
    data: { cancelReason },
  })
}

/**
 * 获取订单列表
 * @param data
 * @returns
 */
export const getOrderListAPI = (data: OrderListParams) => {
  return http<OrderListResult>({
    method: 'GET',
    url: `/member/order`,
    data,
  })
}
